package Session.Cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/sessionservlet2")
public class sessionIndex2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out=resp.getWriter();
        out.print("<h1>Hello Session</h1>");
        HttpSession session=req.getSession();
        String name=session.getAttribute("name").toString();
        String pwd=session.getAttribute("pwd").toString();
        boolean flag=false;
        if (name != null && name!="" &&pwd!=""&&pwd!=null) {
            flag=true;
        }
        else {
            flag=false;
        }
        if (flag) {
            out.print("<h1>欢迎再次登录</h1>");
            System.out.println("name:"+name+"-----"+"pwd:"+pwd);
        }
        else {
            out.print("<h1>session已经失效了</h1>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
